<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            节目名称：<input type="text" name="pname"/>
                        </li>
                        <li>
                        是否紧急：<input type="text" name="isemergency"/>
                        </li>
                        <li class="select-time">
                            <label>申请时间：</label><input class="laydate-icon  layer-date"
                                                       name="downtime"
                                                       id="recivedtime"
                                                       value=""
                                                       readonly="readonly"
                                                       style="width:120px;"
                                                       placeholder="开始日期"
                                                       title="开始日期"/>
                            <span>-</span>

                            <input class="laydate-icon  layer-date"
                                   name="endtime"
                                   id="endtime"
                                   value=""
                                   readonly="readonly"
                                   style="width:120px;"
                                   placeholder="结束日期"
                                   title="结束日期"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="broad:proreApply:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="broad:proreApply:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('broad:proreApply:edit')}]];
    var removeFlag = [[${@permission.hasPermi('broad:proreApply:remove')}]];
    var prefix = ctx + "broad/prolisten";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "节目申请",
            search: false,
            showExport: true,
            columns: [
                {
                    field : 'paid',
                    title : '节目ID',
                    visible: true
                },
                {
                    field : 'pname',
                    title : '节目名称',
                    sortable: true
                },
                {
                    field : 'uname',
                    title : '申请用户',
                    sortable: true
                },
                {
                    field : 'submittime',
                    title : '申请时间',
                    sortable: true
                },
				{
					field : 'isemergency',
					title : '是否紧急',
					sortable: true,
                    formatter:function(value,row) {
                        if(value=="false"){
                            return "不紧急"
                        }else{
                            return "紧急"
                        }
                    }
				},
                {
                    field : 'timelimit',
                    title : '时间要求',
                    sortable: true
                },
                {
                    field : 'iscancel',
                    title : '是否撤回',
                    sortable: true,
                    formatter:function(value,row) {
                      if(value==false ){
                            return "未撤回"
                        }else{
                            return "已撤回"
                        }
                    }
                },
                {
                    field : 'isreply',
                    title : '是否回复',
                    sortable: true,
                    formatter:function(value,row) {
                        if(value==false){
                            return "未回复"
                        }else{
                            return "已回复"
                        }
                    }
                },
                 {
                     field: 'filename',
                     title: '试听',
                     align: 'center',
                     visible: true,
                     formatter: function (value, row, index) {
                         if(value !=""){
                             var actions = '<a class=\"btn btn-xs btn-success\"  onclick=listenmusic(\'' + value + '\')>试听</a>';
                             return actions;
                         }
                     }
                 },
                {
                    field: 'islisten',
                    title: '是否审听',
                    formatter: function (value, row, index) {
                        if(value){
                            return "是";
                        }else{
                           return "否";
                        }

                    }
                },
                {
                    field: 'listenpass',
                    title: '操作',
                    formatter: function (value, row, index) {
                        if(row.isreply==false){
                            return
                        }else if(value==true){
                            return "审听已通过";
                        }else{
                            var actions = '<a class=\"btn btn-xs btn-success\"  onclick=pass(\'' + row.paid + '\')>通过</a> &nbsp;<a class=\"btn btn-xs btn-success\"  onclick=nopass(\'' + row.paid +'\',\'' + row.pname + '\',\'' + row.nopassreason + '\')>不通过</a>';
                            return actions;
                        }

                    }
                }
            ]
        };
        $.table.init(options);
    });
</script>
<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>
<script th:src="@{/js/plugins/layer/layui-v2.4.5/layui/layui.js}"></script>
<script>
    laydate({
        elem:"#recivedtime",
        event:"focus"
    });
    laydate({
        elem:"#recivedtime",
        event:"focus"
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem:"#broad",
            type: 'time',
        });
    });
    laydate({
        elem:"#endtime",
        event:"focus"
    });
    laydate({
        elem:"#endtime",
        event:"focus"
    });
    layui.use('laydate', function(){
        var laydate2 = layui.laydate;

        //执行一个laydate实例
        laydate2.render({
            elem:"#broad",
            type: 'time',
        });
    });
    //试听按钮函数
    function listenmusic(value) {
        layer.open({
            type: 2,
            maxmin: false,
            shade: 0.3,
            title: '试听',
            fix: true,
            area: ["350px", "120px"],
            content: "/broad/prolisten/play",
            shadeClose: false,
            success:function(layero, index){
                $(layero).find("iframe")[0].contentWindow.$("audio").attr('src',"../../"+value);
                var fry_audio=$(layero).find("iframe")[0].contentWindow.$("audio").get('0');
                fry_audio.load();
            }
        })
    }
    function pass(paid) {
        $.get("/broad/prolisten/pass/"+paid, function(data){
            if(data.code==0){
                alert("修改成功");
                $.table.refresh();
            }
        });
    }
    function nopass(paid,pname,nopassreason) {
        layer.open({
            type: 2,
            maxmin: false,
            shade: 0.3,
            title: '试听',
            fix: true,
            area: ["800" + 'px', ($(window).height() - 50) + 'px'],
            content: "/broad/prolisten/nopassreason",
            shadeClose: false,
            btn: ['<i class="fa fa-chat"></i> 确认', '<i class="fa fa-close"></i> 关闭'],
            success:function(layero, index){
                $(layero).find("iframe")[0].contentWindow.$("#paid").val(paid);
                $(layero).find("iframe")[0].contentWindow.$("#pname").val(pname);
                $(layero).find("iframe")[0].contentWindow.$("#nopassreason").val(nopassreason);
            },
            yes: function (index, layero) {
                var selected = $(layero).find("iframe")[0].contentWindow.$("#form-proreApply-nopassreason");
                var formData = new FormData(selected[0])
                if ($.validate.form() && $(layero).find("iframe")[0].contentWindow.$("#nopassreason")) {
                    $.ajax({
                            type : "POST",
                            url : "/broad/prolisten/nopassreason",
                            data : formData,
                            async: false,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success : function(data) {
                                if(data.code==0){
                                    alert('提交成功！');
                                }
                            }
                        }
                    );
                }
                layer.close(index);
                $.table.refresh();
            },
            cancel: function () {return true;}
        })
    }

</script>
</body>
</html>